#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

void *thread_sum(void *arg);

int sum = 0;

int main(int argc, char *argv[])
{
    pthread_t id_t1, id_t2;
    int range1[] = {1, 5};
    int range2[] = {6, 10};
    pthread_create(&id_t1, NULL, thread_sum, range1);
    pthread_create(&id_t2, NULL, thread_sum, range2);

    pthread_join(id_t1, NULL);
    pthread_join(id_t2, NULL);

    printf("结果为: %d \n", sum);

    return 0;
}

void *thread_sum(void *arg)
{
    int start = ((int *)arg)[0];
    int end = ((int *)arg)[1];
    while(start <= end) {
        sum += start;
        start++;
    }
    return NULL;
}